// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import zombie.characters.IsoPlayer;
import zombie.commands.AltCommandArgs;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.core.raknet.VoiceManager;
import zombie.network.GameServer;

@CommandName(
    name = "voiceban"
)
@AltCommandArgs({@CommandArgs(
        required = {"(.+)"},
        optional = "(-true|-false)"
    ), @CommandArgs(
        optional = "(-true|-false)"
    )})
@CommandHelp(
    helpText = "UI_ServerOptionDesc_VoiceBan"
)
@RequiredRight(
    requiredRights = 48
)
public class VoiceBanCommand extends CommandBase {
    public VoiceBanCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() {
        String string = this.getExecutorUsername();
        if (this.getCommandArgsCount() == 2
            || this.getCommandArgsCount() == 1
                && !this.getCommandArg(Integer.valueOf(0)).equals("-true")
                && !this.getCommandArg(Integer.valueOf(0)).equals("-false")) {
            string = this.getCommandArg(Integer.valueOf(0));
        }

        boolean _boolean = true;
        if (this.getCommandArgsCount() > 0) {
            _boolean = !this.getCommandArg(Integer.valueOf(this.getCommandArgsCount() - 1)).equals("-false");
        }

        IsoPlayer isoPlayer = GameServer.getPlayerByUserNameForCommand(string);
        if (isoPlayer != null) {
            string = isoPlayer.getDisplayName();
            VoiceManager.instance.VMServerBan(isoPlayer.OnlineID, _boolean);
            if (_boolean) {
                LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " ban voice " + string);
                return "User " + string + " voice is banned.";
            } else {
                LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " unban voice " + string);
                return "User " + string + " voice is unbanned.";
            }
        } else {
            return "User " + string + " not found.";
        }
    }
}
